package com.xilihui.xlh.business.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xilihui.xlh.BuildConfig;
import com.xilihui.xlh.R;
import com.xilihui.xlh.business.dialogs.GeneralDialogFragment;
import com.xilihui.xlh.business.interfaces.OnPositiveClickListener;
import com.xilihui.xlh.business.util.AppUtil;
import com.xilihui.xlh.core.app.BaseCompatActivity;
import com.xilihui.xlh.core.util.CacheUtil;
import com.xilihui.xlh.core.util.SPUtil;
import com.xilihui.xlh.core.util.ToastUtil;
import com.xilihui.xlh.core.util.YEventBuses;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/4.
 */

public class SettingActivity extends BaseCompatActivity {
    
    @BindView(R.id.tv_cache)
    TextView tv_cache;
    @BindView(R.id.tv_versions)
    TextView tv_version;
    
    @Override
    public int getLayout() {
        return R.layout.activity_setting;
    }

    @Override
    public String initTitle() {
        return "系统设置";
    }

    @Override
    public void initUI(@Nullable Bundle savedInstanceState) {

        
        initCacheSize();
        if (BuildConfig.APP_DEBUG == 0) {
            tv_version.setText("v" + BuildConfig.VERSION_NAME + " DEBUG");
        } else if (BuildConfig.APP_DEBUG == 1) {
            tv_version.setText("v" + BuildConfig.VERSION_NAME + " BETA");
        } else if (BuildConfig.APP_DEBUG == 2) {
            tv_version.setText("v" + BuildConfig.VERSION_NAME);
        }
        
    }

    @Override
    public void initData() {
        
    }
    
    public void initCacheSize(){
        String cacheSize = CacheUtil.CacheSize(this);
        tv_cache.setText(cacheSize);
    }
    
    @OnClick(R.id.ll_setPasswd)
    public void setPasswd(){
        startActivity(new Intent(SettingActivity.this,ForgetActivity.class));
    }
    
    @OnClick(R.id.ll_cache)
    public void clearCache(){
        GeneralDialogFragment.newInstance("确定删除缓存？")
                .setOnPositiveClickListener(new OnPositiveClickListener() {
                    @Override
                    public void onClick() {
                        CacheUtil.deleteCache(CacheUtil.getCacheDirectory(SettingActivity.this, true));
                        initCacheSize();
                        ToastUtil.toastShortPositive("清理缓存成功");
                    }
                }).show(getSupportFragmentManager(), "");
    }
    
    @OnClick(R.id.tv_logout)
    public void logout(){
        SPUtil.remove(SettingActivity.this,SPUtil.IS_LOGIN);
        Intent intent = new Intent(SettingActivity.this,HomeActivity.class);
        intent.putExtra("logout",1);
        startActivity(intent);
        finish();
    }
    
    
    @OnClick(R.id.ll_xieyi)
    public void xieyi(){
        startActivity(new Intent(SettingActivity.this,ProtocolActivity.class));
    }
    
}
